import service from '@/utils/request'
import { useUserStore } from '@/pinia/modules/user'
const userStore = useUserStore()

export const getPlantList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan/list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getSelectPlantList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/common/lov/page', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 作物列表
export const getCropList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/common/lov/page', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 种植阶段列表
export const getStageList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_stage/list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务列表（种植阶段下的任务列表）
export const getTaskList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_stage_task/list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 新增任务
export const addTask = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_stage_task/farm/save', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 删除任务
export const delTask = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_stage_task/delete', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 地块分组列表
export const getLandGroupList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-group/farmland-group-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 地块列表
export const getLandList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-list', data)
      .then(res => {
        resolve(res.data)
      })
  }) 
}

// 地块列表
export const getMinLandList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-mini-list', data)
    // service.post('/boss/tanc-farm-land/tanc-farm-land-list', data)
      .then(res => {
        resolve(res.data)
      })
  }) 
}

// 新增种植计划
export const addFarmPlant = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan/save', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 编辑种植计划
export const editFarmPlant = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan/update', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 删除种植计划
export const delFarmPlant = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan/delete', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

//获取种植计划详情
export const getPlantDetail = (plantHeaderId) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc_plantint_plan/get/${plantHeaderId}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getDropdownList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/common/lov/page', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getUserSelectList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/team/team-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const get_plant_lineList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan_task/list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const get_plant_batch_confirm = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan/confirm', data).then(res => {
        resolve(res.data)
      })
  })
}

export const get_plant_line_confirm = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plant_line/tanc_plant_line-confirm', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getPlantLogList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan_logs/list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getPlantTaskStatistics = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan_task/count', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getPlantLinelistDetail = (id) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc_plantint_plan_task/get/${id}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const editPlantLineItem = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plant_line/tanc_plant_line-edit', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const cancelPlantLineItem = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan/delete/task', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 农场列表,要求展示作物，就用该接口
export const getFarmList = (data) => {
  return new Promise((resolve, reject) => {
    // roleId=1为平台管理员
    if (!data.companyId) {
      const companyId = userStore.userInfo.roleId == 1 ? null : userStore.userInfo.companyId
      data.companyId = companyId
    }

    service.post('/boss/farm/farm-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getTeamFarmList = (id) => {
  return new Promise((resolve, reject) => {
    // roleId=1为平台管理员
    // if (!data.companyId) {
    //   const companyId = userStore.userInfo.roleId == 1 ? null : userStore.userInfo.companyId
    //   data.companyId = companyId
    // }

    service.get('/boss/team/farm-list?companyId=' + id)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 农场列表-不含作物信息（没要求展示作物，就用该接口）
export const getFarmList2 = (data) => {
  return new Promise((resolve, reject) => {
    // roleId=1为平台管理员
    if (!data.companyId) {
      const companyId = userStore.userInfo.roleId == 1 ? null : userStore.userInfo.companyId
      data.companyId = companyId
    }
    service.post('/boss/farm/farm-list-nocrop', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getLandDetail = (farmLandId) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc-farm-land/tanc-farm-land-get?farmLandId=${farmLandId}`)
      .then(res => {
        resolve(res.data)
      })
  })
}
export const getLandNewDetail = (data) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc-farm-land/tanc-farm-land-get`,{params:data})
      .then(res => {
        resolve(res.data)
      })
  })
}
export const getSoilNutrient = (farmLandId) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/farmland-composition/farmland-composition-get?farmLandId=${farmLandId}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const addGroup = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-group/farmland-group-add', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const delGroup = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-group/farmland-group-delete', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getGeologyList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farm-land-geology/farm-land-geology-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const addFarmLand = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-add', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const editFarmLand = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-edit', data)
      .then(res => {
        resolve(res.data)
      })
  })
}
export const delFarmLand = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-delete', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const uploadComposition = (fromData) => {
  return new Promise((resolve, reject) => {
    const config = {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    }
    service.post('/boss/farmland-composition/import-farmland-composition', fromData, config)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const delComposition = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farmland-composition/farmland-composition-delete', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getFarmCount = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/farm/farm-count', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

//获取农场种植记录列表
export const getFarmRecordList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan_task_record/farm/list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

//长势记录
export const getFarmGrowthList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan_task_record/growth/list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getRecordDetail = (id) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc_plantint_plan_task_record/get/${id}`)
      .then(res => {
        resolve(res.data)
      })
  })
}
export const getRecordLandList= (data) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc_plantint_plan_task_record/task/record/land/list`,{params:data})
      .then(res => {
        resolve(res.data)
      })
  })
}



export const getBudget = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/statistical/budget-manage-count', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getAssetTrend = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/statistical/farmland-area-grew-count', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getAssetCondition = (companyId) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/statistical/farmland-asset-status-count?companyId=${companyId}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getFarmDistribution = (companyId) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/statistical/farmland-distribution-count?companyId=${companyId}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getFarmWeather = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/weather/farm-weather-leftside', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getHourWeather = (hourType, location) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/weather/hour?hourType=${hourType}&location=${location}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getDailyWeather = (dayType, location) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/weather/daily2?dayType=${dayType}&location=${location}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getPredictionWeather = (location) => {
  return new Promise((resolve, reject) => {
    service.get(`/api/weather/minutely?location=${location}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getNotifyList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/notify/boss-receipt-notify-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getNotifyDetail = (notifyId) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/notify/sys-notify-get?notifyId=${notifyId}`)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getStageTaskCount = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/statistical/stage-task-count', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getGrowthCompareCount = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/statistical/growth-compare-count', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 获取腾讯地址
export const getTenArea = () => {
  return new Promise((resolve, reject) => {
    service.get('/boss/notify/district')
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getUptM = (farmId) => {
  // return new Promise((resolve,reject)=>{
  //   service.get(`/boss/farmland-composition/template-file?farmId=${farmId}`)
  //   .then(res=>{
  //     resolve(res.data)
  //   })
  // })
  return service({
    url: `/boss/farmland-composition/template-file?farmId=${farmId}`,
    method: 'get',
    responseType: 'blob'
  })
}

export const getPlantedList = (data) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/tanc_plantint_plan_task/task/land/list', {params:data})
      .then(res => {
        resolve(res.data)
      })
  })
}

export const getPlantedDetail = (id) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc_plantint_plan_task_record/get/${id}`)
      .then(res => {
        resolve(res.data)
      })
  })
}
// 新增品种
export const addBreed = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-crop-series/tanc-crop-series-add', data)
      .then(res => {
        resolve(res.data)
      })
  })
}
// 获取天气
export const getFarmlandAcc = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/weather/farmland-acc', data).then(res => { resolve(res.data) })
  })
}


// 获取天气
export const getFarmlandAccList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/weather/farmland-acc-list', data).then(res => { resolve(res.data) })
  })
}


// 巡田情况列表
export const getXuntianList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/common/lov/page', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 作物品种基本信息列表
export const getCropSeriesList = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-crop-series/tanc-crop-series-list', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 批量删除作物品种基本信息
export const deleteCrop = (data) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-crop-series/tanc-crop-series-delete', data)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 负责人列表
export const getFzuserList = (params) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/tanc_plantint_plan_task_fzuser/list', { params })
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务地块列表
export const getTaskLandList = (data) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/tanc_plantint_plan_task/task/land/list`,{params:data})
      .then(res => {
        resolve(res.data)
      })
  })
}
// 根据参数生成方案模型
export const getGenerate = (params) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/tanc_model_lib/generate', { params })
      .then(res => {
        resolve(res.data)
      })
  })
}


// 根据参数名获取参数值
export const getParamName = (paramName) => {
  return new Promise((resolve, reject) => {
    service.get(`/boss/sys_param/get/param_name/${paramName}`, {})
      .then(res => {
        resolve(res.data)
      })
  })
}


// 任务地块列表-土壤类型列表(BOSS)
export const getLandTypeList = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land-type/tanc-farm-land-type-list', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务地块-土地权属列表(BOSS)
export const getBelongList = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land-belong/tanc-farm-land-belong-list', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务地块-地块标签列表
export const getLandTagsList = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-land-tags/tanc-land-tags-list', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务地块-新增土地权属(BOSS)
export const addLandBelong = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land-belong/tanc-farm-land-belong-add', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务地块-新增地块标签
export const addLandTags = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-land-tags/tanc-land-tags-add', params)
      .then(res => {
        resolve(res.data)
      })
  })
}
// 任务地块-删除土地权属(BOSS)
export const deleteBelong = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land-belong/tanc-farm-land-belong-delete', params)
      .then(res => {
        resolve(res.data)
      })
  })
}
// 任务地块-删除地块标签(BOSS)
export const deleteTags = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-land-tags/tanc-land-tags-delete', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务地块-批量编辑地块信息
export const landUpdateBatch = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-update-batch', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务地块-批量修改地块标签(BOSS)
export const landTagsUpdateBatch = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-farm-land/tanc-farm-land-tags-update-batch', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 历史温度列表
export const getHistoryTemp = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/weather-area/get-history', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 校验是否存在生长模型(BOSS)
export const checkPlantingModel = (params) => {
  return new Promise((resolve, reject) => {
    service.get('/boss/tanc_model_lib/check', {params:params})
      .then(res => {
        resolve(res.data)
      })
  })
}


// 删除地块标签
export const deleteLandTags = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc-land-tags/tanc-land-tags-delete2', params)
      .then(res => {
        resolve(res.data)
      })
  })
}


// 农事处理任务记录列表(
export const getFarmTaskList = (params) => {
  return new Promise((resolve, reject) => {
    service.post('/boss/tanc_plantint_plan_task_record/list', params)
      .then(res => {
        resolve(res.data)
      })
  })
}

// 任务记录地块处理次数统计(BOSS)
export const getLandHandCount = (data) => {
  return new Promise((resolve, reject) => {
    service.post(`/boss/tanc_plantint_plan_task_record/land/count`,data)
      .then(res => {
        resolve(res.data)
      })
  })
}


//统计地块处理最近长势颜色(BOSS)
export const getLandGrowthCount = (data) => {
  return new Promise((resolve, reject) => {
    service.post(`/boss/tanc_plantint_plan_task_record/land/growth`,data)
      .then(res => {
        resolve(res.data)
      })
  })
}
